<template>
  <div class="w640 dg-list">
    <h4 class="art-title"  v-if="count>0">共:<span v-text="count" style="color:#ff6700"></span>条
    </h4>
    <yd-infinitescroll :callback="loadList" ref="infinitescrollDemo">
      <yd-list theme="4" slot="list">
        <yd-list-item v-for="item,key in dgList"  :key="key" type="div" class="commentlist">
          <a slot="img"  :href="'#/dgAdd/'+item._id">
            <img style="height: 1.5rem!important;"   :src="item.avatarUrl">
          </a>
          <div slot="title">
              <span class="item-titles">{{item.nickName}}</span>
              <div class="cm-content">{{item.content}}</div>
              <div class="cm-time">{{item.time}}</div>
            <div class="delete-btns" @click="removeItem(item._id)">
              <img src="../assets/images/shanchu.png" />
            </div>
          </div>
        </yd-list-item>
      </yd-list>
      <!-- 数据全部加载完毕显示 -->
      <span slot="doneTip">没有数据啦~~</span>
    </yd-infinitescroll>
    <div class="list-addbtn"><router-link to="dgSelect">首页</router-link></div>
  </div>
</template>

<script>
  import Vue from 'vue';
  import {Toast,Confirm} from 'vue-ydui/dist/lib.rem/dialog';
  import {ListTheme, ListItem} from 'vue-ydui/dist/lib.rem/list';
  import {InfiniteScroll} from 'vue-ydui/dist/lib.rem/infinitescroll';

  Vue.component(InfiniteScroll.name, InfiniteScroll);
  Vue.component(ListTheme.name, ListTheme);
  Vue.component(ListItem.name, ListItem);
  export default {
    name: "commentList",
    data() {
      return {
        page: 0,
        limit: 10,
        dgList: [],
        count: 0,
        dg_type:'景点',
      }
    },
    mounted() {
      document.title="景点列表";
      this.loadList();
    },
    updated(){

    },
    created(){
      var ls=localStorage.getItem("dgUser");
      if(!ls || ls!=='qun'){
        this.$router.replace( '/dgLogin');
      }
    },
    methods: {
      changes(){
        this.$store.commit('changeName','哈哈');
        console.log(this.$store.state.myname)
      },
      loadList() {
        this.$axios.post("/comment/commentList", {
          page: this.page,
          limit: this.limit,
          dg_type:this.dg_type,
          listType:'all'
        }).then((res) => {
          let data = res.data.result;
          this.count = data.count;
          const _list = data.list;

          this.dgList = [...this.dgList, ..._list];

          if (_list.length < this.limit) {
            /* 所有数据加载完毕 */
            this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.loadedDone');
            return;
          }

          /* 单次请求数据完毕 */
          this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.finishLoad');

          this.page++;
        });
      },
      removeItem(id){
        Confirm({
          title: '提示',
          mes: '确定删除吗？',
          opts: () => {
            this.$axios.post("/comment/delComment",{
              comment_id:id
            })
              .then((res)=>{
                let jsons=res.data;
                Toast({mes:jsons.msg,time:1000,callback: () => {
                    this.dgList=[];
                    this.loadList();
                  }});
              }).catch(()=>{})
          }
        });
      },
      selectType(v){
        this.dgList=[];
        this.loadList();
      }

    },

  }
</script>

